package com.bba.manager.order.controller;

import com.bba.manager.common.model.order.Order;
import com.bba.manager.common.model.order.Purchase;
import com.bba.manager.common.model.order.VO.orderVO;
import com.bba.manager.common.util.ResponseVO;
import com.bba.manager.order.service.impl.OrderServiceImpl;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zzy
 * @since 2025-08-12
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderServiceImpl orderService;



    @DeleteMapping("/{id}")
    public ResponseVO delete(@PathVariable String id) {
        orderService.removeById(id);
        return ResponseVO.success();
    }

    @PostMapping("/update")
    public ResponseVO update(@RequestBody Order order) {
        boolean b = orderService.updateById(order);
        return ResponseVO.success(b);
    }

    @GetMapping("/{id}")
    public ResponseVO getOrder(@PathVariable String id) {
        Order order = orderService.getById(id);
        return ResponseVO.success(order);
    }
    @GetMapping("/getList")
    public ResponseVO getall() {
        return ResponseVO.success(orderService.listall());
    }
    @GetMapping("/getTotalPriceByDate")
    public ResponseVO getgetTotalPriceByDate(@RequestParam Integer employeeId,@RequestParam String dateStr){
        BigDecimal totalPriceByDate = orderService.getTotalPriceByDate(employeeId, dateStr);
        return ResponseVO.success(totalPriceByDate);
    }
}
